<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" type="text/css" href="../../bootstrap-3.3.7/dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../../bootstrap-3.3.7/dist/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="../../css/index.css" />
<link rel="stylesheet" type="text/css" href="../../css/personal.css" />
<link rel="stylesheet" type="text/css" href="../../css/background.css" />
<script type="text/javascript" src="../../bootstrap-3.3.7/dist/js/jquery.min.js"></script>
<script type="text/javascript" src="../../bootstrap-3.3.7/dist/js/bootstrap.js"></script>
<!-- bootstrap表格插件 -->	
<script src="../../bootstrap-3.3.7/dist/js/bootstrap-table.js"></script>
<link href="../../bootstrap-3.3.7/dist/css/bootstrap-table.css" rel="stylesheet" />

<script src="../../bootstrap-3.3.7/dist/js/bootstrap-table-zh-CN.js"></script> 
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="../../bootstrap-3.3.7/docs/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>
<body>
	<h4 class="heading">我的上传</h4>
	<div class="myline"></div>
	<div class="col-md-12" >
		<form id="formSearch" class="form-horizontal">
                 <div class="form-group" style="margin-top:15px;margin-bottom:0px">
                 	<div class="col-md-2">
                 		<select class="combobox" id="status" style="height: 30px; width: 100%; float: left">
                 			<option value="">全部</option>
							<option value="未审核">未审核</option>
							<option value="通过">通过</option>
						</select>
                 	 </div>
                     <label class="control-label col-sm-1" for="txt_search_departmentname">题名</label>
                     <div class="col-md-5">
                         <input type="text" class="form-control" id="txt_search_departmentname">
                     </div>
                     <div class="col-md-1" style="text-align:left;">
                         <button type="button" style="margin-left:10px" id="btn_query" class="btn btn-primary">查询</button>
                     </div>
                     <div class="col-md-2" style="margin-left:20px;text-align:left;">
                         <button type="button"  id="btn_delete" class="btn btn-primary">删除所选</button>
                     </div>
                 </div>
             </form>
	</div>
	<div class="col-md-12">
          <table id="tb_departments">
          </table>
    </div>
</body>
<script type="text/javascript">
	$(function() {
		 $("#status option[value='全部']").attr("selected", true);
		 //$("#status").find("option:contains('未审核')").attr("selected",true);

		//1.初始化Table
		var oTable = new TableInit();
		oTable.Init();

		//2.初始化Button的点击事件
		var oButtonInit = new ButtonInit();
		oButtonInit.Init();

	});
	var TableInit = function() {
		var oTableInit = new Object();
		//初始化Table
		oTableInit.Init = function() {
			$('#tb_departments')
					.bootstrapTable(
							{
								url : 'getUpload', //请求后台的URL（*）
								method : 'get', //请求方式（*）
								toolbar : '#toolbar', //工具按钮用哪个容器
								striped : true, //是否显示行间隔色
								cache : false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
								pagination : true, //是否显示分页（*）
								sortable : true, //是否启用排序
								sortOrder : "asc", //排序方式
								queryParams : oTableInit.queryParams,//传递参数（*）
								sidePagination : "server", //分页方式：client客户端分页，server服务端分页（*）
								pageNumber : 1, //初始化加载第一页，默认第一页
								pageSize : 10, //每页的记录行数（*）
								pageList : [10, 25, 50, 100], //可供选择的每页的行数（*）
								search : false, //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
								strictSearch : true,
								showColumns : true, //是否显示所有的列
								showRefresh : true, //是否显示刷新按钮
								minimumCountColumns : 2, //最少允许的列数
								clickToSelect : true, //是否启用点击选中行
								height : 650, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
								uniqueId : "ID", //每一行的唯一标识，一般为主键列
								showToggle : true, //是否显示详细视图和列表视图的切换按钮
								cardView : false, //是否显示详细视图
								detailView : false, //是否显示父子表
								columns : [
										{
											checkbox : true
										},
										{
											field : 'name',
											title : '题名',
											width : '30%',
											formatter : function(value, row,
													index) {
												var element = "<a onclick='check(\""
														+ row.id
														+ "\")' data-id='"
														+ row.id
														+ "'><span class='text-primary'>"
														+ row.name
														+ "</span></a>&nbsp;&nbsp";

												return element;
											}
										},
										{
											field : 'author',
											title : '作者',
											width : '12%'
										},
										{
											field : 'part',
											title : '发布部门',
											width : '11%'
										},
										{
											field : 'time',
											title : '发布时间',
											width : '11%'
										},
										{
											field : 'library',
											title : '库',
											width : '10%'
										},
										{
											field : 'download',
											title : '下载',
											width : '3%'
										},
										{
											field : 'browse',
											title : '浏览',
											width : '3%'
										},
										{
											field : 'status',
											title : '状态',
											width : '8%'
										},
										{
											field : 'operate',
											title : '操作',
											width : '15%',
											formatter : function(value, row,
													index) {
												var element;
												
													element='<a href="#" data-id="\''+ row.id+ '\'" onclick="deleteone(\''+ row.id+ '\',\''+row.infourl+'\',\''+row.name+'\',\''+row.kutype+'\',\''+row.status+'\')"><span class=\'text-primary\'>删除</span></a>&nbsp;&nbsp;'
													+'<a href="#" data-id="\''+ row.id+ '\'" onclick="updateInfo(\''+ row.id+ '\')"><span class=\'text-primary\'>修改</span></a>';
												
												return element;
											}
										}]
							});
		};
		//得到查询的参数
		oTableInit.queryParams = function(params) {
			var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
				limit : params.limit, //页面大小
				offset : params.offset, //页码初始开始值
				departmentname : $("#txt_search_departmentname").val(),//题名
				status :$("#status").val()
			};
			return temp;
		};
		return oTableInit;
	};

	var ButtonInit = function() {
		var oInit = new Object();
		oInit.Init = function() {
			//初始化页面上面的按钮事件
			$('#btn_query').bind('click', function() {
				$('#tb_departments').bootstrapTable('refreshOptions',{pageNumber:1});
				/* $('#tb_departments').bootstrapTable("refresh", {
					url : "getUpload"
				}); */
			});
			$('#btn_delete').bind(
					'click',
					function() {
						var deleteRows = $('#tb_departments').bootstrapTable("getSelections");
						if(deleteRows.length==0){
							alert("请选择要删除的数据");
							return;
						}
						/* var strIds=[];
						var strurls=[];
						for(var i=0;i<deleteRows.length;i++){
							if(deleteRows[i].status=="通过"){
								alert("不能删除已通过审核的知识！");
								return;
							}
							strIds.push(deleteRows[i].id);
							strurls.push(deleteRows[i].info_url);
						} */
						var delIds=[];
						var delurls=[];
						var strIds=[];
						var strurls=[];
						var strnames=[];
						var strkutypes=[];
						for(var i=0;i<deleteRows.length;i++){
							delIds.push(deleteRows[i].id);
							delurls.push(deleteRows[i].infourl);
							if(deleteRows[i].status=="通过"){
								strIds.push(deleteRows[i].id);
								strurls.push(deleteRows[i].infourl);
								strnames.push(deleteRows[i].name);
								strkutypes.push(deleteRows[i].kutype);
							}						
						}
						
						var delids=delIds.join(",");
						var ids=strIds.join(",");
						if (confirm("您确定删除这"+deleteRows.length+"条数据吗")) {
							$.ajax({
								type : 'POST',
								url : 'deleteUploadsy',
								data : {
									delids:delids,
									delurls:delurls,
							        ids :ids,
							        urls:strurls,
							        names:strnames,
							        kutypes:strkutypes,
								},
								traditional: true,
								success : function(result) {
									$('#tb_departments').bootstrapTable("refresh", {
										url : "getUpload"
									});
								}
							});
						}	
					});
		};
		return oInit;
	};
	function deleteone(id,infourl,name,kutype,status){
		if (confirm("您确定删除这条数据吗")) {
			$.ajax({
				type : 'POST',
				url : 'deleteUploady',
				data : {
			        id :id,
			        infourl:infourl,
			        name:name,
			        kutype:kutype,
			        status:status
				},
				success : function(result) {
					$('#tb_departments').bootstrapTable("refresh", {
						url : "getUpload"
					});
				}
			});
		}	
	};
	//查看知识详情
	function check(id) {
		window.open("../information/getInfoDetial?info_id="+id);
	}
	function updateInfo(id) {
		$("#refresh").load("../information/getUpdateview?info_id="+id);
	}
</script>
</html>